package com.firefoxking.mysite.service.log.impl;

import com.firefoxking.mysite.dao.LogsMapper;
import com.firefoxking.mysite.entity.Logs;
import com.firefoxking.mysite.service.log.LogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private LogsMapper logsMapper;

    @Override
    public void addLog(String action, String data, String ip, Integer authorId) {
        Logs logs = new Logs();
        logs.setAuthorId(authorId);
        logs.setIp(ip);
        logs.setData(data);
        logs.setAction(action);
        logsMapper.addLogs(logs);
    }

    @Override
    public void deleteLogById(Integer id) {
        logsMapper.deleteLogsById(id);
    }

    @Override
    public PageInfo<Logs> getLogs(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Logs> logs = logsMapper.getLogs();
        PageInfo<Logs> pageInfo = new PageInfo<>(logs);
        return pageInfo;
    }
}
